/**动态计算当前月份的周数 */
export const getWeeksNumber = () => {
  const getWeeksInMonth = (year, month) => {
    const firstDayOfMonth = new Date(year, month, 1)
    const lastDayOfMonth = new Date(year, month + 1, 0)
    const daysInMonth = lastDayOfMonth.getDate()
    const firstDayOfWeek = firstDayOfMonth.getDay() // + 1 // 0 表示周日，1 表示周一，以此类推

    // 计算当前月份的自然周数
    const weeks = []
    let week = []
    for (let day = 1; day <= daysInMonth; day++) {
      const currentDate = new Date(year, month, day)
      const currentDayOfWeek = currentDate.getDay()

      // 如果是新的一周开始，将之前的一周添加到 weeks 数组中，并重新创建一个新的周数组
      if (currentDayOfWeek === firstDayOfWeek && week.length > 0) {
        weeks.push(week)
        week = []
      }

      week.push(currentDate)
    }
    // 处理月末的不完整周
    while (week.length % 7 !== 0) {
      week.push(null) // 填充月末的不完整周
    }
    // 将最后一个周添加到 weeks 数组中
    if (week.length > 0) {
      weeks.push(week)
    }

    return weeks
  }
  const now = new Date()
  const currentYear = now.getFullYear()
  const currentMonth = now.getMonth()
  const weeksInMonth = getWeeksInMonth(currentYear, currentMonth)
  console.log('本月的周数量', weeksInMonth.length)
  return weeksInMonth.length
}
